#ifndef _MODEL_H_
#define _MODEL_H_

#define NUM_SENSOR_BANKS 5
#define MAX_NUM_TRAINS 10
#define MAX_NODES 72
#define NODE_MAX_EDGES 3
#define SWITCH_CURVED 0
#define SWITCH_STRAIGHT 1

typedef struct __track_edge {
  int dest;
  int distance;
} track_edge;

typedef struct __track_switch {
  track_edge ahead[2]; // (curved, straight)
  track_edge behind;
  int set;
} track_switch;

typedef struct __track_sensor {
  track_edge ahead;
  track_edge behind;
  track_edge filler[1];
  char trig_forward, trig_back;
} track_sensor;

typedef struct __track_stop {
  track_edge ahead;
  track_edge filler[2];
} track_stop;

typedef struct __track_node {
  enum {
    NODE_SWITCH,
    NODE_SENSOR,
    NODE_STOP,
  } type;
  char name[5];
  int id, id2;
  union {
    track_switch sw;
    track_sensor se;
    track_stop st;
    track_edge edges[4];
  };
  int x, y; // location (for GUI)
} track_node;

typedef struct __track_model {
  int num_nodes;
  track_node nodes[MAX_NODES];
  int sensor_nodes[NUM_SENSOR_BANKS*16];
} track_model;

void TrackModelInit(track_model* tm, char track_id);

#endif
